﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using System.IO;
using for7raid.vkPlayer;
using System.Windows.Controls.Primitives;

namespace Utils
{
    public partial class NewVersionPopup : ResourceDictionary
    {
        public NewVersionPopup()
        {
            InitializeComponent();

        }

        private void Close(object sender, RoutedEventArgs e)
        {
            ((((sender as Button).Parent as Grid).Parent as Border).Parent as Popup).IsOpen = false;
        }

        public CustomPopupPlacement[] placePopup(Size popupSize,
                                           Size targetSize,
                                           Point offset)
        {
           

            double primScreenHeight = System.Windows.SystemParameters.FullPrimaryScreenHeight;
            double primScreenWidth = System.Windows.SystemParameters.FullPrimaryScreenWidth;
            double Top = (primScreenHeight - targetSize.Height) / 2;
            double Left = (primScreenWidth - targetSize.Width) / 2;


            CustomPopupPlacement placement1 =
               new CustomPopupPlacement(new Point(Left, Top), PopupPrimaryAxis.Vertical);

            

            return new CustomPopupPlacement[] { placement1 };
        }

        public void txtLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            var tbox = sender as TextBlock;
            Stream file = Application.GetResourceStream(new Uri("newversion.txt", UriKind.Relative)).Stream;
            byte[] text = new byte[file.Length];
            file.Read(text, 0, (int)file.Length);
            tbox.Text = Encoding.UTF8.GetString(text);

        }
        
    }
}
